import axios from 'axios';
import showMessage from '@/utils/showMessage';
//文章博客内容
export async function getBLogBody(id) {
    const resp = await axios({ url: `/api/blog/${id}`, method: 'get' });
    if (resp.data.code === 0) {
        return resp.data.data;
    } else {
        return showMessage(resp.data.msg, 'error', 1000, Home)
    }
}
// 提交评论
export async function submitData(nickname, content, blogId) {
    const resp = await axios({
        url: `/api/comment`,
        method: 'post',
        body: {
            nickname: nickname, //昵称
            content: content, //评论内容
            blogId: blogId, //评论博客id
        }
    });
    if (resp.data.code === 0) {
        return resp.data.data;
    } else {
        return showMessage(resp.data.msg, 'error', 1000, )
    }
}

//分页获取评论
export async function submitComment(page = 1, limit = 10, blogId = -1, keyword = '') {
    const resp = await axios({
        url: '/api/comment',
        method: 'get',
        params: {
            page: page, //当前页码
            limit: limit, //当前页容量
            blogId: blogId, //所属文章
            keyword: keyword //模糊查询关键字
        }
    });
    if (resp.data.code === 0) {
        return resp.data.data;
    } else {
        return showMessage(resp.data.msg, 'error', 1000, Home)
    }
}